def set_stage():
""" Sets up the stage for the game """
stage.set_background("soccerfield")
stage.disable_floor()
def add_player():
""" Adds a player to the stage for the user to control """
def main():
""" Sets up the program and calls other functions """
set_stage()
main()
t = codesters.Teacher()
defs = t.find_block("def")
sprites = stage.get_all_sprites()
sprite_lines = t.find_function("Sprite")
add_players = t.find_text("add_player")
def above_def(line_number, def_list):
""" Returns the name of the nearest function and the distance above the given line number """
function_name = ""
distance = line_number - def_list[0][0]
for func in def_list:
if line_number - func[0] <= distance and line_number - func[0] > 0:
function_name = func[1]
distance = line_number - func[0]
return function_name, distance
try:
tval1 = sprites[0].get_image_name()
tval_x = sprites[0].get_x()
tval_y = sprites[0].get_y()
except:
tval1 = "DNE"
tval_x = "DNE"
tval_y = "DNE"
try:
tval2 = sprite_lines[0][1]
tval2 = tval2.replace(' ','').lower()
tval_indent = t.get_indent_at_line(sprite_lines[0][0])
except:
tval2 = "DNE"
tval_indent = "DNE"
try:
tval3 = above_def(sprite_lines[0][0], defs)[0]
except:
tval3 = "DNE"
try:
tval4 = add_players[1][1]
tval4 = tval4.replace(' ','').lower()
tval4_indent = t.get_indent_at_line(add_players[1][0])
except:
tval4 = "DNE"
tval4_indent = "DNE"
try:
tval5 = above_def(add_players[1][0], defs)[0]
except:
tval5 = "DNE"
t1 = TestObjective()
t1.add_success("player1" in tval1, "Great job!")
t1.add_failure(tval1 == "DNE" or tval1 == [], "Did you add Player 1 to the add_player() function?")
t1.add_creative("player1" not in tval1, "That's a good sprite too!")
t2 = TestObjective()
t2.add_success("player=" in tval2 and tval_indent == 4, "Great job!")
t2.add_failure(tval2 == "DNE", "Did you add Player 1 to the add_player() function?")
t2.add_failure("player=" not in tval2, "Did you rename the sprite to player?")
t2.add_failure(tval_indent < 4 or tval_indent > 4, "Did you indent Player 1 within add_player()?")
t3 = TestObjective()
t3.add_success("add_player" in tval3, "Great job!")
t3.add_failure("add_player" not in tval3, "Did you put Player 1 in the add_player()?")
t4 = TestObjective()
t4.add_success("player=" in tval4 and "add_player()" in tval4 and tval4_indent == 4, "Great job!")
t4.add_failure(tval4 != "DNE" and "player=" not in tval4, "Did you change my_var to player in the Function Call into Variable?")
t4.add_failure(tval4 != "DNE" and "add_player()" not in tval4, "Did you change my_function to add_player in the Function Call into Variable?")
t4.add_failure(tval4 != "DNE" and (tval4_indent < 4 or tval4_indent > 4), "Did you indent Function Call into Variable within main()?")
t4.add_failure(tval4 == "DNE", "Did you add a Function Call into Variable to main()?")
t5 = TestObjective()
t5.add_success("main" in tval5, "Great job!")
t5.add_failure("main" not in tval5, "Did you put Function Call into Variable in main()?")
# NOTE: These tests don't work correctly if the sprite creation line is placed in another funciton...
t6 = TestObjective()
t6.add_success(tval_x == 0 and tval_y == -155, "Great job!")
t6.add_failure(tval_x != 0 or tval_y != -155, "Did you update the player's position to (0, -155)?")
t6.add_failure(tval_x == "DNE" or tval_y == "DNE", "Did you add Player 1 within add_player()?")
tester = TestManager()
tester.add_test_list([t2, t3, t4, t5, t1, t6])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Enviar Trabajo
-
Actividad Siguiente
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)